package com.lin.manager.mq.service.impl;

import com.lin.manager.mq.dao.MqMessageDao;
import com.lin.manager.mq.entity.MqMessageeEntity;
import com.lin.manager.mq.service.MqMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @作者: 林江
 * @创建时间: 2024/4/14
 * @功能:
 */
@Service
public class MqMessageServiceImpl implements MqMessageService {
    @Autowired
    MqMessageDao mqMessageDao;

    @Override
    public void save(MqMessageeEntity messagee) {
        // 查询 -- 判断是否投递过消息
        MqMessageeEntity mqMessagee = mqMessageDao.selectById(messagee.getId());
        if (mqMessagee == null) {
            mqMessageDao.insert(messagee);
        } else {
            mqMessagee.setContent(messagee.getContent());
            mqMessageDao.updateById(mqMessagee);
        }
    }

    @Override
    public void updateStatus(String id, Integer status, String cause) {
        MqMessageeEntity messagee = new MqMessageeEntity();
        messagee.setId(id);
        messagee.setStatus(status);
        messagee.setCause(cause);
        mqMessageDao.updateById(messagee);
    }

    @Override
    public MqMessageeEntity getById(String correlationId) {
        return mqMessageDao.selectById(correlationId);
    }
}
